function ImageLazada_Index()
{
	this.renameAllFile	= function(p)
	{
		showWaiting();
		$.post
		(
			HOST + '/folder/rename-all-file/',
			{
				'p'	: p
			},
			function(data)
			{
				window.location.href = window.location.href;
			}
		);
	}
	
	this.doUpdateStatus	= function(i, st, st_o, f)
	{
		this.waitProcess(i, 'wait', 'status');
		$.post
		(
			HOST_ADMIN + '/folder/status-image/',
			{
				'i'		: i,
				'st'	: st,
				'st_o'	: st_o,
				'f'		: f
			},
			function()
			{
				if(st==4 || st_o==4){
					/*$('#image_'+i).hide();*/
				}
				ImageLazada_Index.waitProcess(i, 'done', 'status');
			}
		);
	}
	
	this.waitProcess	= function(i, v, t)
	{
		var html	= '';
		if(v=='wait'){
			html 	= '<img src="img/wait.gif" />';
		}
		else if(v=='done'){
			html	= '<img src="img/ok.gif" />';
		}
		var e	= $('#process_'+t+'_'+i);
		e.html(html);
	}
	
	this.doUpdatePsd	= function(i, f)
	{
		this.waitProcess(i, 'wait', 'psd');
		$.post
		(
			HOST_ADMIN + '/folder/psd/',
			{
				'i'		: i,
				'f'		: f
			},
			function()
			{
				ImageLazada_Index.waitProcess(i, 'done', 'psd');
			}
		);
	}
	
	/* Replace */
	this.displayCpanel	= function(i, t, v)
	{
		var ePanel		= $('#panel_'+t+'_'+i);
		var eReplace	= $('#replace_'+t+'_'+i);
		ePanel.hide();
		eReplace.hide();
		if(v=='cpanel'){
			ePanel.show();
		}else if(v=='replace'){
			eReplace.show();
		}
		this.replaceWait(i,t);
	}
	
	this.doSubmitReplace	= function(i,t)
	{
		this.replaceWait(i, t, 'wait');
		return true;
	}
	
	this.replaceWait	= function(i, t, v)
	{
		var eW	= $('#wait_'+t+'_'+i);
		var eS	= $('#submit_'+t+'_'+i);
		eW.hide();
		eS.hide();
		if(v=='wait'){
			eW.show();
		}else{
			eS.show();
		}
	}
	
	this.replaceDone	= function(i, t)
	{
		this.displayCpanel(i, t, 'cpanel');
		if(t=='img')
		{
			var e 	= $('#img_'+i);
			var v	= e.attr('src');
			e.attr('src', v+'?='+Math.random() );
		}
	}
	/* Replace */
	
	
	this.submitCreateFolder	= function()
	{
		var e = $('#strFolderName');
		if( !e.val() )
		{
			e.focus();
			return false;
		}
		showWaiting();
		return true;
	}
	
	this.removeImage	= function(p, i, index)
	{
		var msg	= 'Do you really want to delete this image?';
		if( confirm(msg) )
		{
			if(i){
				$('#image_'+i).hide();
			}
			else{
				$('#image_'+index).hide();
			}
			
			$.post(
				HOST + '/folder/remove-image/',
				{
					'p'	: p,
					'i'	: i
				},
				function(data){}
			);
		}
	}
	
	/* Rename */
	this.initRename	= function(i, v){
		var eInfo	= $('#infoName_'+i);
		var eEdit	= $('#editName_'+i);
		
		eInfo.addClass('hide');
		eEdit.addClass('hide');
		
		if(v=='info'){
			eInfo.removeClass('hide');
		}
		else if(v=='edit'){
			eEdit.removeClass('hide');
		}
	}
	
	this.doRename	= function(i)
	{
		var id	= 'strName_'+i;
		var e	= $('#'+id);
		if( !e.val() ){
			e.focus();
			return false;
		}
		return true;
	}
	/* Rename */
}

var ImageLazada_Index = new ImageLazada_Index();